package com.effects;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

/**
 * @author sad
 */
public class RainbowEffect extends BasicEffect {

    private final double[] tArray = new double[78];
    private double offset = 20;
    int index = 0;

    @Override
    public String getEffectName() {
        return "Rainbow";
    }

    @Override
    public String getId() {
        return "rainbow";
    }

    @Override
    public BufferedImage getImage(byte[] pcm) {
        double[]value=spectrum(pcm);
        Graphics g = image.getGraphics();
        g.drawImage(image, -1, 0, null);
        g.setColor(Color.green);
        
        int height = image.getHeight();
        for (int i = 0; i < height; i++) {
            image.setRGB(image.getWidth() - 1, i, getRainbow((int)(value[i+4]*60), 40).getRGB());
        }

        offset += (Math.tan(Math.toRadians(index + Math.random() * 20))) * 20;
        index += Math.random() * 20;
        return image;
    }
}
